<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8"/>
    <title>E-Wallet-ES商城</title>
    <link rel="stylesheet" th:href="@{/css/style.css}"/>
    <script th:src="@{/js/jquery.min.js}"></script>

    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/bootstrap-theme.min.css">
    <script src="js/bootstrap.min.js"></script>

    <script th:src="@{js/pay/pageskip.js}"></script>

    <script th:src="@{js/axios.min.js}"></script>
    <script th:src="@{js/vue.min.js}"></script>
    <script th:src="@{js/elementui.min.js}"></script>
</head>

<body class="pg">
<div>
    <nav class="navbar navbar-default navbar-fixed-top navbar-inverse">
        <div class="container">
            <div class="navbar-header">
                <img alt="Brand" th:src="@{images/logo3.png}">
            </div>
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                    <li><a href="/">首页</a></li>
                    <li><a href="/goodsIndex">网上商城</a></li>
                    <li><a href="/trans">转账</a></li>
                    <li><a href="/settlement">清算</a></li>
                    <li><a href="/withdraw">提现</a></li>
                </ul>
                <ul class="nav navbar-nav navbar-right">
                    <a href="/login" th:if="${logined}">
                        <button type="button" class="btn btn-default navbar-btn">Sign in</button>
                    </a>
                    <li class="dropdown" th:if="${!logined}">
                        <a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                           aria-expanded="false">
                            Signed in as <span th:text="${username}"></span><span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu">
                            <li><a th:href="${'/user/'+username}">用户中心</a></li>
                            <li role="separator" class="divider"></li>
                            <li><a href="/logout">注销</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </nav>
</div>

<div class="page" id="app">
    <div id="mallPage" class=" mallist tmall- page-not-market ">

        <!-- 头部搜索 -->
        <div id="header" class=" header-list-app">
            <div class="headerLayout">
                <div class="headerCon ">
                    <!-- Logo-->
                    <h1 id="mallLogo">
                        <!--                        <img th:src="@{/images/logo.jpg}" alt="">-->
                    </h1>

                    <div class="header-extra">

                        <!--搜索-->
                        <div id="mallSearch" class="mall-search">
                            <form name="searchTop" class="mallSearch-form clearfix">
                                <fieldset>
                                    <legend>E-wallet搜索</legend>
                                    <div class="mallSearch-input clearfix">
                                        <div class="s-combobox" id="s-combobox-685">
                                            <div class="s-combobox-input-wrap">
                                                <input v-model="keyword" type="text" autocomplete="off" value="dd"
                                                       id="mq"
                                                       class="s-combobox-input" aria-haspopup="true">
                                            </div>
                                        </div>
                                        <button type="submit" @click.prevent="searchKey" id="searchbtn">搜索</button>
                                    </div>
                                </fieldset>
                            </form>
                            <ul class="relKeyTop">
                                <li><a @click.prevent="searchKey2('java')">java</a></li>
                                <li><a @click.prevent="searchKey2('前端')">前端</a></li>
                                <li><a @click.prevent="searchKey2('linux')">Linux</a></li>
                                <li><a @click.prevent="searchKey2('大数据')">大数据</a></li>
                                <li><a @click.prevent="searchKey2('理财')">理财</a></li>
                                <li><a @click.prevent="searchKey2('机器学习')">机器学习</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- 商品详情页面 -->
        <div id="content">
            <div class="main">
                <!-- 品牌分类 -->
                <form class="navAttrsForm">
                    <div class="attrs j_NavAttrs" style="display:block">
                        <div class="brandAttr j_nav_brand">
                            <div class="j_Brand attr">
                                <div class="attrKey" style="height: 30px">品牌</div>
                                <div class="attrValues">
                                    <ul class="av-collapse row-2">
                                        <li><a href="#"> E-Wallet </a></li>
                                        <li><a href="#"> Java </a></li>

                                    </ul>

                                </div>

                            </div>
                        </div>
                    </div>
                </form>

                <!-- 排序规则 -->
                <div class="filter clearfix">
                    <a class="fSort fSort-cur">综合<i class="f-ico-arrow-d"></i></a>
                    <a class="fSort">人气<i class="f-ico-arrow-d"></i></a>
                    <a class="fSort">新品<i class="f-ico-arrow-d"></i></a>
                    <a class="fSort">销量<i class="f-ico-arrow-d"></i></a>
                    <a class="fSort" @click.prevent="sortGood">价格<i class="f-ico-triangle-mt"></i><i
                            class="f-ico-triangle-mb"></i></a>

                    <el-input-number v-model="pageNo" @change="searchKey" :min="1" :max="10" label="请输入页码"></el-input-number>
                </div>

                <!-- 商品详情 -->
                <div class="view grid-nosku">

                    <div class="product" v-for="result in results">
                        <div class="product-iWrap">
                            <!--商品封面-->
                            <div class="productImg-wrap">
                                <a class="productImg" :href="'/payinit/'+result.oldtitle+'/'+result.price">
                                    <img :src="result.img">
                                </a>
                            </div>
                            <!--价格-->
                            <p class="productPrice">
                                <em><b>¥</b>{{result.price}}</em>
                            </p>
                            <!--标题-->
                            <p class="productTitle">
                                <a v-html="result.title"> </a>
                            </p>
                            <!-- 店铺名 -->
                            <div class="productShop">
                                <span>店铺： E-wallet </span>
                            </div>
                            <!-- 成交信息 -->
                            <p class="productStatus">
                                <span>月成交<em>999笔</em></span>
                                <span>评价 <a>3</a></span>
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </div>


    </div>
</div>


<!-- 前端使用vue -->

<script>

    new Vue({
            //  绑定元素
            el: "#app",
            data: {
                pageNo:"1",
                keyword: '',
                aKeyword: '',
                results: [],//搜索的结果
                des : 1,
            },
            methods: {
                searchKey() {
                    var keyword = this.keyword;
                    var pageNo = this.pageNo;
                    console.log(keyword);
                    console.log(pageNo);

                    axios.get('search/' + keyword + "/" + pageNo).then(response => {
                        console.log(response.data);
                        this.results = response.data; //数据获得成功 vue双向绑定

                    })
                },
                searchKey2(val) {
                    this.keyword = val;
                    this.pageNo = "1";
                    axios.get('search/' + val + "/1").then(response => {
                        console.log(response.data);
                        this.results = response.data; //数据获得成功 vue双向绑定

                    })
                },


                sortGood() {
                    var des = this.des;
                    this.des =  -1 * des;
                    //写法二
                    function sortData(a, b) {
                        //console.log(b.price);

                        return des * (b.price - a.price);
                    }

                    this.results.sort(sortData);
                    // this.des = -1 * this.des;

                }


            },
            created() {
                this.searchKey2("书")
            }
        }
    )
</script>


</body>
</html>